package com.itheima.app.manager;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.domain.db.Answers;
import com.itheima.domain.db.User;
import com.itheima.domain.vo.ConclusionVo;
import com.itheima.domain.vo.PaperListVo;
import com.itheima.service.db.TestSoulService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class SoulManager {

    @Reference
    private TestSoulService testSoulService;



    //查询问卷列表
    public ResponseEntity findPaperListVo() {
        //获取线程id
        Long userId = UserHolder.get().getId();

        //rpc调用传入数据 获得vo
        List<PaperListVo> paperListVos = testSoulService.queryPaperList(userId);

        //返回
        return ResponseEntity.ok(paperListVos);
    }

    //提交
    public ResponseEntity submitPaper(Map<String, List<Answers>> map) {
        //获取线程userid
        Long userId = UserHolder.get().getId();
        //调用rpc
        String s = testSoulService.submitTestPaper(map, userId);

        return ResponseEntity.ok(s);

    }

    public ResponseEntity getReport(Long id) {
        Long userId = UserHolder.get().getId();
        ConclusionVo report = testSoulService.getReport(id, userId);
        return ResponseEntity.ok(report);
    }
}
